package com.heatup.apt.api.controller;

import com.heatup.apt.api.service.*;
import com.heatup.apt.common.constants.ErrorCodeConstants;
import com.heatup.apt.common.util.JsonTools;
import com.heatup.apt.common.util.JsonUtils;
import com.heatup.apt.common.util.RequestTools;
import com.heatup.apt.common.util.ResponseTools;
import com.heatup.apt.model.api.ApiResultModel;
import com.heatup.apt.model.api.coach.CoachResultModel;
import com.heatup.apt.model.coach.CoachInfo;
import com.heatup.apt.model.course.CoachFeeDetailVo;
import com.heatup.apt.model.course.CoursePrivteFeeVO;
import com.heatup.apt.model.order.OrderFinished;
import com.heatup.apt.model.user.UserInfo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by b3st9u on 16/8/20.
 */

@RequestMapping(value = "/coach")
@Controller
public class CoachController extends BaseController {
    protected static final Logger log = LoggerFactory.getLogger(CoachController.class);

    @Resource
    private CoachService coachService;
    @Resource
    private CoachCourseFeeService coachCourseFeeService;
    @Resource
    private CourseService courseService;
    @Resource
    private CourseSignService courseSignService;
    @Resource
    private OrderService orderService;
    @Resource
    private CoachPrivateSortService coachPrivateSortService;

    @ResponseBody
    @RequestMapping(value = "/get", method = {RequestMethod.POST, RequestMethod.GET})
    private String getCoachResult(HttpServletRequest request) {
        int coach_id = RequestTools.RequestInt(request, "id", 0);
        String type = RequestTools.RequestString(request, "type", null);
        String callback = RequestTools.RequestString(request, "callback", "");
        ApiResultModel<CoachResultModel> apiResultModel = new ApiResultModel<>();
        String msg = "";
        // 表示是通过banner 跳转过来的 需要轮排获取教练信息
        if ("banner".equals(type) && coach_id == 0) {
            // 通过轮排获取教练Id
            coach_id = coachPrivateSortService.checkAndReturnNextCoachId(null, this.getUserId());
        }
        int ret = ApiResultModel.RET_SUCCESS;
        try {
            CoachResultModel coachModel = coachService.queryCoachById(coach_id, this.getUserId());
            if (coachModel == null || coachModel.getId() == null) {
                ret = ApiResultModel.RET_SUCCESS;
                msg = ErrorCodeConstants.Code.COACH_NOT_FOUND.getMessage();
            }
            apiResultModel.setData(coachModel);
        } catch (Exception e) {
            ret = ApiResultModel.RET_ERROR;
            msg = ErrorCodeConstants.Code.SYSTEM_ERROR_EXCEPTION.getMessage() + e.getMessage();
            log.error(ErrorCodeConstants.Code.SYSTEM_ERROR_EXCEPTION.getMessage() + e.getMessage() + e.toString(), e);
        }
        apiResultModel.setRet(ret);
        apiResultModel.setMsg(msg);
        apiResultModel.setLogined(isLogined());
        return ResponseTools.CallBackResultJsonP(JsonTools.jsonSer(apiResultModel), callback);
    }


    /**
     * 根据教练手机号码查询教练信息
     *
     * @param mobile 教练手机号码
     * @return 教练信息
     */
    @RequestMapping(value = "/coachInfo")
    @ResponseBody
    public String getCoachInfo(String mobile, @RequestParam(defaultValue = "") String callback) {

        ApiResultModel<CoachInfo> apiResultModel = new ApiResultModel<>(this.isLogined());

        apiResultModel.setData(coachService.queryCoachAndPwdByMobile(mobile));

        apiResultModel.setRet(ApiResultModel.RET_SUCCESS);
        apiResultModel.setMsg("");
        if (apiResultModel.getData() == null) {
            apiResultModel.setRet(ApiResultModel.RET_ERROR);
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_NOT_FOUND.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_NOT_FOUND.getMessage());
        }
        return ResponseTools.CallBackResultJsonP(JsonTools.jsonSer(apiResultModel), callback);

    }

    /**
     * 教练端 团课列表
     *
     * @param pageIndex 页面码 1开始
     * @param pageSize  页面大小 默认10
     * @param type      记录类型 默认 0我的授课 1授课记录
     * @param callback  回调
     * @return 团课列表
     */
    @RequestMapping(value = "/getTeamCourseList")
    @ResponseBody
    public String getTeamCourseList(@RequestParam Integer pageIndex,
                                    @RequestParam Integer pageSize,
                                    @RequestParam(defaultValue = "0") String type,
                                    @RequestParam(defaultValue = "") String callback) {

        ApiResultModel apiResultModel = new ApiResultModel(this.isLogined());

        if (!apiResultModel.isLogined()) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());

        } else {

            if (pageIndex > 0)
                --pageIndex;
            if (pageSize <= 0)
                pageSize = 10;

            Map<String, Object> paramMap = new HashMap<>();
            paramMap.put("pageIndex", pageIndex);
            paramMap.put("pageSize", pageSize);
            paramMap.put("type", type);

            String mobile = getUserInfo().getMobile();
            if (StringUtils.isBlank(mobile)) {
                apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getCode());
                apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getMessage());
            } else {
                paramMap.put("mobile", mobile);
                try {
                    apiResultModel = courseService.queryCoachTeamCourseListByMobile(paramMap);
                } catch (Exception e) {
                    e.printStackTrace();
                    log.error("教练端 查询团课列表出错 blank - -! ----->" + e.getMessage() + e.toString() + e, e);
                }
            }
        }
        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);
    }

    /**
     * 教练端 檬营列表
     *
     * @param pageIndex 页面码 1开始
     * @param pageSize  页面大小 默认10
     * @param type      记录类型 默认 0我的授课 1授课记录
     * @param callback  回调
     * @return 檬营列表
     */
    @RequestMapping(value = "/getCampCourseList")
    @ResponseBody
    public String getCampCourseList(@RequestParam Integer pageIndex,
                                    @RequestParam Integer pageSize,
                                    @RequestParam(defaultValue = "0") String type,
                                    @RequestParam(defaultValue = "") String callback) {

        ApiResultModel apiResultModel = new ApiResultModel(this.isLogined());

        if (!apiResultModel.isLogined()) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());

        } else {

            if (pageIndex > 0)
                --pageIndex;
            if (pageSize <= 0)
                pageSize = 10;

            Map<String, Object> paramMap = new HashMap<>();
            paramMap.put("pageIndex", pageIndex);
            paramMap.put("pageSize", pageSize);
            paramMap.put("type", type);

            String mobile = getUserInfo().getMobile();
            if (StringUtils.isBlank(mobile)) {
                apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getCode());
                apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getMessage());
            } else {
                paramMap.put("mobile", mobile);
                try {
                    apiResultModel = courseService.queryCoachCampCourseListByMobile(paramMap);
                } catch (Exception e) {
                    e.printStackTrace();
                    log.error("教练端 查询檬营列表出错 blank - -! ----->" + e.getMessage() + e.toString() + e, e);
                }
            }
        }

        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);
    }

    /**
     * 教练端 私教列表
     *
     * @param pageIndex   页面码   1开始
     * @param pageSize    页面大小 默认10
     * @param privateType 课程类型 1:私教课 2:体测 3:体验 4:咨询
     * @param type        记录类型 默认 0我的授课 1授课记录
     * @param callback    回调
     * @return 私教列表
     */
    @RequestMapping(value = "/getPrivateCourseList")
    @ResponseBody
    public String getPrivateCourseList(@RequestParam Integer pageIndex,
                                       @RequestParam Integer pageSize,
                                       @RequestParam Integer privateType,
                                       @RequestParam(defaultValue = "0") String type,
                                       @RequestParam(defaultValue = "") String callback) {

        ApiResultModel<Map<String, Object>> apiResultModel = new ApiResultModel<Map<String, Object>>(this.isLogined());
        if (!apiResultModel.isLogined()) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());

        } else {

            if (pageIndex > 0)
                --pageIndex;
            if (pageSize <= 0)
                pageSize = 10;

            Map<String, Object> paramMap = new HashMap<>();
            paramMap.put("pageIndex", pageIndex);
            paramMap.put("pageSize", pageSize);
            paramMap.put("type", type);
            paramMap.put("privateType", privateType);

            String mobile = getUserInfo().getMobile();
            if (StringUtils.isBlank(mobile)) {
                apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getCode());
                apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getMessage());
            } else {
                paramMap.put("mobile", mobile);
                try {
                    apiResultModel.setData(courseService.queryCoachPrivateCourseListByMobile(paramMap));
                } catch (Exception e) {
                    e.printStackTrace();
                    apiResultModel.setMsg("教练端 查询私教列表出错 blank - -! ----->" + e.getMessage() + e.toString() + " \n根原因 --> " + e.getCause());
                    log.error("教练端 查询私教列表出错 blank - -! ----->" + e.getMessage() + e.toString() + " \n根原因 --> " + e.getCause(), e);
                    return ResponseTools.CallBackResultJsonP(JsonUtils.toJsonStrWithDateFormat(apiResultModel), callback);
                }
            }
        }

        return ResponseTools.CallBackResultJsonP(JsonUtils.toJsonStrWithDateFormat(apiResultModel, "yyyy-MM-dd HH:mm"), callback);
    }

    /**
     * 教练 课程(签到)详情
     *
     * @param courseId 课程ID
     * @param callback 回调
     * @return 课程详情
     */
    @RequestMapping(value = "/getCourseInfo")
    @ResponseBody
    public String getCourseInfo(@RequestParam Integer courseId,
                                @RequestParam(defaultValue = "") String callback) {

        ApiResultModel<Map<String, Object>> apiResultModel = new ApiResultModel(this.isLogined());
        if (getUserInfo() == null) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());
        } else {
            String mobile = getUserInfo().getMobile();
            if (StringUtils.isBlank(mobile)) {
                apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getCode());
                apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getMessage());
            } else {
                try {
                    apiResultModel.setData(courseSignService.chaxuCoachCourseInfoById(courseId, mobile));
                } catch (Exception e) {
                    log.error("教练端 查询课详情出错 blank - -! ---> " + e.getMessage() + e.toString() + e);
                }
            }
        }
        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);
    }


    /**
     * 教练 檬营开启/关闭签到
     *
     * @param courseId     课程ID
     * @param courseNumber 课时序号
     * @param type         签到类型 1开启 0关闭
     * @return success--> true 成功 false 失败
     */
    @RequestMapping(value = "/campSignIn")
    @ResponseBody
    public String campSignIn(@RequestParam Integer courseId,
                             @RequestParam Integer courseNumber,
                             @RequestParam Integer type, String callback) {

        ApiResultModel apiResultModel = new ApiResultModel(this.isLogined());
        if (getUserInfo() == null) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());
        } else {
            String mobile = getUserInfo().getMobile();
            if (StringUtils.isBlank(mobile)) {
                apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getCode());
                apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getMessage());
            } else {
                boolean success = false;
                try {
                    success = courseSignService.campCourseSignIn(courseId, courseNumber, getUserId(), type);
                } catch (Exception e) {
                    apiResultModel.setMsg(e.getMessage());
                    log.error("教练檬营开启/关闭签到时出错 --->" + e.getMessage() + e.toString() + e, e);
                }
                Map<String, Object> resultMap = new HashMap<>();
                resultMap.put("success", success);
                apiResultModel.setData(resultMap);
            }
        }
        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);

    }

    /**
     * 教练详情 我的教练
     *
     * @return 教练信息
     */
    @RequestMapping(value = "/info")
    @ResponseBody
    public String coachInfo(String callback) {

        ApiResultModel<Map> apiResultModel = new ApiResultModel<>(this.isLogined());
        UserInfo userInfo = getUserInfo();
        if (userInfo == null) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());
        } else {
            String mobile = userInfo.getMobile();
            Map<String, Object> resultMap = new HashMap<>();
            if (StringUtils.isBlank(mobile)) {
                apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getCode());
                apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getMessage());
            } else {
                //查询 教练信息
                CoachInfo coachInfo = coachService.queryCoachAndPwdByMobile(mobile);
                if (coachInfo != null) {

                    //已上总课时 累计学员
                    OrderFinished orderFinished = orderService.queryCoachFinishedCourseCount(mobile);

                    resultMap.put("coachInfo", coachInfo);
                    resultMap.put("courseCount", orderFinished.getCourseCount() == null ? 0 : orderFinished.getCourseCount());
                    resultMap.put("userCount", orderFinished.getUserCount() == null ? 0 : orderFinished.getUserCount());
                } else {
                    resultMap.put("msg", "notCoach");
                }
            }
            apiResultModel.setData(resultMap);
        }
        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);
    }

    /**
     * 教练课时费 按年月份明细
     *
     * @param year 年 2016-9999 必传
     * @return 教练课时费 按年月份明细
     */
    @RequestMapping("/coachCourseFeeMonth")
    @ResponseBody
    public String coachCourseFeeMonth(@RequestParam Integer year, String callback) {

        UserInfo userInfo = getUserInfo();
        ApiResultModel<Object> apiResultModel = new ApiResultModel<>(this.isLogined());
        if (userInfo == null) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());
        } else {
            apiResultModel.setData(coachCourseFeeService.queryCoachFeeMonth(userInfo.getMobile(), year));
        }

        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);

    }

    /**
     * 教练月度调整课时费详情
     *
     * @param year  要查询的年 2016-9999 必传
     * @param month 要查询的月 1-12 必传
     * @return 教练月度调整课时费详情
     */
    @RequestMapping("/coachAdjustFeeMonth")
    @ResponseBody
    private String coachAdjustFeeMonth(Integer year, Integer month, String callback) {

        ApiResultModel<Map> apiResultModel = new ApiResultModel<>(this.isLogined());
        UserInfo userInfo = getUserInfo();
        if (userInfo == null) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());
        } else {

            String mobile = userInfo.getMobile();
            if (StringUtils.isBlank(mobile)) {
                apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getCode());
                apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getMessage());
            } else {
                apiResultModel.setData(coachService.queryCoachAdjustFeeMonth(mobile, year, month));
            }
        }

        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);

    }

    /**
     * 团课统计
     *
     * @param request
     * @param callback
     */
    @RequestMapping(value = "/fee_list", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String feeList(HttpServletRequest request,
                          @RequestParam(defaultValue = "") String callback) {

        int pageIndex = RequestTools.RequestInt(request, "pageIndex", 0);
        int pageSize = RequestTools.RequestInt(request, "pageSize", 1000);
        ApiResultModel<Map<String, Object>> apiResultModel = new ApiResultModel<Map<String, Object>>(isLogined());


        if (this.getUserInfo() == null) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());
        } else {
            String mobile = this.getUserInfo().getMobile();
            if (StringUtils.isBlank(mobile)) {
                apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getCode());
                apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getMessage());
            } else {
                //查询 教练信息+进店密码
                CoachInfo coachInfo = coachService.queryCoachAndPwdByMobile(mobile);
                //    	smsLogPage = smslogService.selectSmsLogPage(smsLogPage, paramsMap);
                Map<String, Object> paramsMap = this.dealParam(request, coachInfo.getId());
                List<CoachFeeDetailVo> list = courseService.queryCoachFeeDetail(paramsMap);
                Map<String, Object> dataMap = new HashMap<String, Object>();
                dataMap.put("feeList", list);
                dataMap.put("feeListCount", list.size());
                apiResultModel.setData(dataMap);
            }
        }

        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);
    }

    /**
     * 私教费用统计明细
     *
     * @param request
     * @param callback
     */
    @RequestMapping(value = "/private_fee_list", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String privateFeeList(HttpServletRequest request,
                                 @RequestParam(defaultValue = "") String callback) {
        int pageIndex = RequestTools.RequestInt(request, "pageIndex", 0);
        int pageSize = RequestTools.RequestInt(request, "pageSize", 1000);
        ApiResultModel<Map<String, Object>> apiResultModel = new ApiResultModel<Map<String, Object>>(isLogined());


        if (getUserInfo() == null) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());
        } else {
            String mobile = this.getUserInfo().getMobile();
            if (StringUtils.isBlank(mobile)) {
                apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getCode());
                apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getMessage());
            } else {
                CoachInfo coachInfo = coachService.queryCoachAndPwdByMobile(mobile);
                //    	smsLogPage = smslogService.selectSmsLogPage(smsLogPage, paramsMap);
                Map<String, Object> paramsMap = this.dealParam(request, coachInfo.getId());
                List<CoursePrivteFeeVO> list = coachService.queryCoachPrivateFeeDetail(paramsMap);

                Map<String, Object> dataMap = new HashMap<String, Object>();

                dataMap.put("priFeeList", list);
                dataMap.put("priFeeListCount", list.size());
                apiResultModel.setData(dataMap);
            }
        }
        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);
    }

    /**
     * 檬营费用统计明细
     *
     * @param request
     * @param callback
     */
    @RequestMapping(value = "/camp_fee_list", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String campFeeList(HttpServletRequest request,
                              @RequestParam(defaultValue = "") String callback) {
        ApiResultModel<Map<String, Object>> apiResultModel = new ApiResultModel<>(this.isLogined());
        if (getUserInfo() == null) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());
        } else {
            String mobile = this.getUserInfo().getMobile();
            if (StringUtils.isBlank(mobile)) {
                apiResultModel.setErrorCode(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getCode());
                apiResultModel.setMsg(ErrorCodeConstants.Code.COACH_MOBILE_NOT_BIND.getMessage());
            } else {
                CoachInfo coachInfo = coachService.queryCoachAndPwdByMobile(mobile);
                //    	smsLogPage = smslogService.selectSmsLogPage(smsLogPage, paramsMap);
                Map<String, Object> paramsMap = this.dealParam(request, coachInfo.getId());
                Map<String, Object> map = coachService.queryCoachCampFeeDetail(paramsMap);
                apiResultModel.setData(map);
            }
        }
        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);
    }

    /**
     * 参数处理
     */
    private Map<String, Object> dealParam(HttpServletRequest request, Integer coachId) {
//    	int pageIndex = RequestTools.RequestInt(request, "pageIndex", 0);
//        int pageSize = RequestTools.RequestInt(request, "pageSize", 10);
        String yearMonth = RequestTools.RequestString(request, "yearMonth", null);
        Integer storeId = RequestTools.RequestInt(request, "storeId", 0);
        Integer courseId = RequestTools.RequestInt(request, "courseId", 0);
        Integer orderId = RequestTools.RequestInt(request, "orderId", 0);
        Map<String, Object> paramsMap = new HashMap<>();
//        paramsMap.put("pageIndex", pageIndex);
//        paramsMap.put("pageSize", pageSize);
        paramsMap.put("coachId", coachId);
        paramsMap.put("storeId", storeId == 0 ? null : storeId);
        paramsMap.put("yearMonth", yearMonth);
        paramsMap.put("courseId", courseId == 0 ? null : courseId);
        paramsMap.put("orderId", orderId == 0 ? null : orderId);
        return paramsMap;
    }

    /**
     * 根据门店查询私教列表
     *
     * @param request
     * @param response
     * @param //storeId   门店Id
     * @param //coachType 教练类型
     * @return
     */
    @ResponseBody
    @RequestMapping("/get_private_list")
    public String getPrivateList(HttpServletRequest request, HttpServletResponse response) {
        ApiResultModel<Object> apiResultModel = new ApiResultModel<>();
        String callback = RequestTools.RequestString(request, "callback", null);
        Integer storeId = RequestTools.RequestInt(request, "storeId", 0);    // 根据门店来查询 不选择门店就查询所有支持私教的教练
        Integer coachType = RequestTools.RequestInt(request, "coachType", 2); // 教练类型 1 团课 2 私教 3 训练营
        Map<String, Object> parmasMap = new HashMap<>();
        try {
            parmasMap.put("storeId", storeId);
            if (coachType.intValue() == 2) {
                parmasMap = coachService.queryCoachPrivateList(parmasMap);
                apiResultModel.setData(parmasMap);
                apiResultModel.setRet(ApiResultModel.RET_SUCCESS);
                apiResultModel.setMsg("查询成功！");
            }
        } catch (Exception e) {
            apiResultModel.setData("系统异常");
            apiResultModel.setRet(ApiResultModel.RET_ERROR);
            apiResultModel.setMsg("系统异常！");
            log.debug("=========== getPrivateList error:" + e.toString() + e.getCause(), e);
        }
        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);
    }


    /**
     * 查询私教订单限制
     *
     * @param serviceType 9 体测 10 体验
     * @author blank 2017/8/24 下午6:25
     */
    @RequestMapping("getPrivateOrderLimit")
    @ResponseBody
    public String getPrivateOrderLimit(Integer serviceType, String callback) {

        ApiResultModel<Map<String, Object>> apiResultModel = new ApiResultModel<>(this.isLogined());
        if (getUserInfo() == null) {
            apiResultModel.setErrorCode(ErrorCodeConstants.Code.USER_NOT_LOGIN.getCode());
            apiResultModel.setMsg(ErrorCodeConstants.Code.USER_NOT_LOGIN.getMessage());
        } else {

            try {
                apiResultModel.setData(coachService.queryPrivateOrderLimit(serviceType));
            } catch (Exception e) {
                log.error("查询私教体测/体验订单出错 ---->> " + e.toString() + " 根原因  " + e.getCause());
                apiResultModel.setRet(ApiResultModel.RET_ERROR);
                apiResultModel.setMsg("查询私教体测/体验订单出错 ---->> " + e.toString() + " 根原因  " + e.getCause());
            }

        }
        return ResponseTools.CallBackResultJsonP(JsonUtils.obj2Json(apiResultModel), callback);
    }
}
